﻿@model MvcApplication5.Models.CreateModel

@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/News/AdminLayout.cshtml";    
}

@{    
    //var category = (from item in Model where (item.NewsId == 1) select item);
}


<h2>Edit</h2>

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script lang ="JavaScript">    
        function validateForm()
        {
            var x=document.forms["form1"]["News.Title"].value;
            if (x==null || x=="")
            {
                alert("Bạn chưa nhập tiêu đề tin");
                return false;
            }
        }
        $(function () {
            $("#datepicker").datepicker({ dateFormat: "mm/dd/yy" });
        });

        function pick() {
            var x = document.forms["form1"]["file"].value.replace("C:\\fakepath\\", "");
            document.forms["form1"]["News_Image"].value = x;           
        }
</script>

<form action="/News/Edit/" method="post" name="form1" onsubmit="return validateForm()">
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>News</legend>                                      
        @Html.HiddenFor(model => model.News.NewsId)
        <div class="label">
            Chuyên mục:
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(m => m.News.CategoryId, new SelectList(Model.categoryList, "CategoryId", "Name",Model.News.Category))
            @Html.ValidationMessageFor(model => model.News.CategoryId)
        </div>        
        <div class="label">
            Tiêu đề:
        </div>
        <div class="editor-field">
            <input type="text" id="News_Title" name="News.Title" value="@Model.News.Title" size="91"/>
            @Html.ValidationMessageFor(model => model.News.Title)
        </div>

        <div class="label">
            Ảnh đại diện:
        </div>
        <div class="editor-field">                                    
            <input type="text" size="91" name="News.Image" id="News_Image" value="@Model.News.Image"/>
            <input runat="server" id="file" name="file" style="WIDTH: 308px" type="file" onchange="pick()"/>                                                
        </div>
        <div class="label">
            Tóm tắt:
        </div>
        <div class="editor-field">
            <textarea id="News_Summary" name="News.Summary" rows="5" cols="70">@Model.News.Summary</textarea>
        </div>        
        <div class="label">
            Nội dung bài viết:
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.News.Content, new { @id = "ckeContent" })
            <script type="text/javascript">
                CKEDITOR.replace("ckeContent", {
                    filebrowserBrowseUrl: '/Plugins/ckfinder_aspnet_2.3.1/ckfinder/ckfinder.html',
                    filebrowserImageBrowseUrl: '/Plugins/ckfinder_aspnet_2.3.1/ckfinder/ckfinder.html?Type=Images',
                    filebrowserFlashBrowseUrl: '/Plugins/ckfinder_aspnet_2.3.1/ckfinder/ckfinder.html?Type=Flash',
                    filebrowserUploadUrl: '/Plugins/ckfinder_aspnet_2.3.1/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
                    filebrowserImageUploadUrl: '/Plugins/ckfinder_aspnet_2.3.1/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
                    filebrowserFlashUploadUrl: '/Plugins/ckfinder_aspnet_2.3.1/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash',                    
                });                
            </script>           
            @Html.ValidationMessageFor(model => model.News.Content)
        </div>
        <table  style="font-size:12px; width:1100px;">
            <tr>
                <td>
                    <div class="label">
                        Tác giả:
                    </div>
                    <div class="editor-field">
                        @Html.DropDownListFor(m => m.News.AuthorId, new SelectList(Model.authorList, "AuthorId", "Name",Model.News.Author),"-- Chọn tác giả --")
                        @Html.ValidationMessageFor(model => model.News.AuthorId)
                    </div>
                    <div class="label">
                        <label>Tin liên quan:</label>
                    </div>
                    <div class="news-edit-add">
                        <a href="/News/Add/@Model.News.NewsId?FromPage=@ViewBag.FromPage&UserType=@ViewBag.UserType">Thêm</a>
                        <a href="/News/Remove/@Model.News.NewsId?FromPage=@ViewBag.FromPage&UserType=@ViewBag.UserType">Xóa</a>
                    </div>                                                    
                    <div class="editor-field">
                        <select name="relatedList" id="relatedList" multiple="multiple" style="width:300px; height:100px;">
                            @if (Model.relatedNewsList != null)
                            {
                                foreach (var item in Model.relatedNewsList)
                                {
                                    <option>@item.Title</option>
                                }
                            }                    
                        </select>
                    </div>
                    <div class="label">
                        <label>Tag</label>
                    </div>
                    <div class="news-edit-add">
                        <a href="/News/AddTag/@Model.News.NewsId?FromPage=@ViewBag.FromPage&UserType=@ViewBag.UserType">Thêm</a>
                        <a href="/News/RemoveTag/@Model.News.NewsId?FromPage=@ViewBag.FromPage&UserType=@ViewBag.UserType">Xóa</a>
                    </div>                                                    
                    <div class="editor-field">
                        <select name="Tag" id="Tag" multiple="multiple" style="width:300px; height:100px;">
                            @if (Model.tagList != null)
                            {
                                foreach (var item in Model.tagList)
                                {
                                    <option>@item.TagName</option>
                                }
                            }                    
                        </select>
                    </div>
                </td>
                <td style="text-align:right; padding-right:20px;">
                    <div style="margin-bottom:10px;">Là bài hot: @Html.CheckBoxFor(model => model.News.isHot)</div>                    
                    <div style="margin-bottom:10px;">Tiêu điểm: @Html.CheckBoxFor(model => model.News.focus)</div>
                    <div style="margin-bottom:10px;">Nổi bật trang chủ: <input type="checkbox"/></div>                                                                             
                </td>
            </tr>
        </table>                    
        <input type="hidden" id="News_level" name="News.level" value="0" />
        <input type="hidden" id="News_ViewCount" name="News.ViewCount" value="@Model.News.ViewCount" />        
        <input type="hidden" id="News_position" name="News.position" value="@Model.News.position" />
        <input type="hidden" id="News_position2" name="News.position2" value="@Model.News.position2" />        
        @*<input type="hidden" id="News_PublishedDate" name="News.PublishedDate" value="@Model.News.PublishedDate" />*@
        <input type="hidden" id="News_LastModifiedDate" name="News.LastModifiedDate" value="@DateTime.Now" />
        <input type="hidden" id="News_AccountId" name="News.AccountId" value="@int.Parse(Session["UserId"].ToString())" />
        <input type="hidden" id="UserType" name="UserType" value="@ViewBag.UserType" />
        <input type="hidden" id="FromPage" name="FromPage" value="@ViewBag.FromPage" />        
        <div>
            <input type="submit" name="submitButton" value="Lưu" />
            @if(ViewBag.UserType == "CTV"){
                <input type="submit" name="submitButton" value="Gửi lên chờ biên tập" />
            }
            @if(ViewBag.UserType == "BTV" && ViewBag.FromPage != "EditingList"){
                <input type="submit" name="submitButton" value="Nhận biên tập" />
            }
            @if(ViewBag.UserType == "TBT"){
                if (ViewBag.FromPage != "Published"){
                    if (ViewBag.FromPage != "PublishWaitList" && ViewBag.FromPage != "TempList"){
                        <input type="submit" name="submitButton" value="Nhận duyệt" />
                    }                
                    <input type="submit" name="submitButton" value="Xuất bản" />
                }
                <div style="margin-top:20px;">Chọn thời gian xuất bản: </div>
                <div class="publish-time">                    
                    <input type="text" id="datepicker" name="datepicker" value="@Model.News.PublishedDate.Value.ToShortDateString()" readonly="readonly"/>
                    <select name="Hour" id="Hour">
                        <option value="0" selected>Chọn giờ</option>
                        @for (int j = 0; j <= 23; j++)
                        {
                            if (j == Model.News.PublishedDate.Value.Hour){
                                <option value="@j" selected>@j</option>
                            }else{
                                <option>@j</option>
                            }
                                
                        }   
                    </select>
                    <select name="Minute" id="Minute">
                        <option value="0" selected>Chọn phút</option>
                        @for (int j = 0; j <= 59; j++)
                        {
                            if (j == Model.News.PublishedDate.Value.Minute){
                                <option value="@j" selected>@j</option>
                            }else{
                                <option>@j</option>
                            }
                                
                        }   
                    </select>
                    <select name="Second" id="Second">
                        <option value="0" selected>Chọn giây</option>
                        @for (int j = 0; j <= 59; j++)
                        {
                            if (j == Model.News.PublishedDate.Value.Second){
                                <option value="@j" selected>@j</option>
                            }else{
                                <option>@j</option>
                            }
                                
                        }   
                    </select>
                </div>            
            }
        </div>                                                        
    </fieldset>
    @*<input type="hidden" id="News_focus" name="News.focus" value="@Model.News.focus" />*@
    @*<input type="hidden" id="News_isHot" name="News.isHot" value="@Model.News.isHot" />*@
</form>
